package leetcode;

import java.util.ArrayList;
import java.util.List;

public class LC43 {
    public static void main(String[] args) {

    }
    public int kthSmallest(TreeNode root, int k) {
        List<Integer> ans = new ArrayList<>();
        kthSmallest(root,ans);
        return ans.get(k-1);
    }
    public void kthSmallest(TreeNode root,List<Integer> ans) {
        if (root == null) return;
        kthSmallest(root.left,ans);
        ans.add(root.val);
        kthSmallest(root.right,ans);
    }


}
